<link rel="stylesheet" href="{{base_url()}}syslib/jqwidgets/styles/jqx.base.css" type="text/css" />
<script type="text/javascript" src="{{base_url()}}syslib/jqwidgets/jqxcore.js"></script>
<script type="text/javascript" src="{{base_url()}}syslib/jqwidgets/jqxswitchbutton.js"></script>
<script type="text/javascript" src="{{base_url()}}syslib/jqwidgets/jqxcheckbox.js"></script>
<script type="text/javascript" src="{{base_url()}}syslib/jqwidgets/gettheme.js"></script>

<script type="text/javascript">
    $(document).ready(function () {
        var theme = getTheme()
        $('.swb').each(function(){ 
            $(this).jqxSwitchButton({
                thumbSize   :   '18px',
                disabled    :   $(this).hasClass("dis"), 
                height      :   18, width: 60, theme: theme, 
                checked     :   $(this).hasClass("on") 
            });
        });
        $('.swb').bind('checked', function (event){
            var currentAu=$("#"+event.target.id).parents(".user-box-info").find("input.authority-value");
            var stroldAu=$("#"+event.target.id).parents(".user-box-info").find("input.current-authority-value").val();
            var au=event.target.id.split("-");
            var ID=au[0],auth=au[1];
            var strcurrentau=currentAu.val();
            strcurrentau=strcurrentau.replace(";"+auth+";","");
            strcurrentau=strcurrentau+";"+auth+";";
            currentAu.val(strcurrentau);
            if(strcurrentau!=stroldAu){
                $("#"+event.target.id).parents(".user-box-info").find(".apply-aurhority").show();
            }else{
                $("#"+event.target.id).parents(".user-box-info").find(".apply-aurhority").hide();
            }
        });
        $('.swb').bind('unchecked', function (event){
            var currentAu=$("#"+event.target.id).parents(".user-box-info").find("input.authority-value");
            var stroldAu=$("#"+event.target.id).parents(".user-box-info").find("input.current-authority-value").val();
            var au=event.target.id.split("-");
            var ID=au[0],auth=au[1];
            var strcurrentau=currentAu.val();
            strcurrentau=strcurrentau.replace(";"+auth+";","");
            currentAu.val(strcurrentau);
            if(strcurrentau!=stroldAu){
                $("#"+event.target.id).parents(".user-box-info").find(".apply-aurhority").show();
            }else{
                $("#"+event.target.id).parents(".user-box-info").find(".apply-aurhority").hide();
            }
        });
        $(".user-opt").click(function (){
            $(this).parents(".user-box-info").find(".user-up-down-graded").toggle();
        });
        $(".apply-aurhority").click(function(){
            var ID=$(this).parents(".user-box-info").find(".user-id").val();
            var authority=$(this).parents(".user-box-info").find(".authority-value").val();
            if(isrunning) return;
            var url = "{{base_url()}}APanel/user/apply/940cc81cec5c7e119162e62bd57710f0d"
            var data={
                ID          : ID,
                Authority   :authority
            }
            isrunning=true;
            jqxAjax(url,data,function(result){
                isrunning=false;
                try{
                    if(result.code<0){
                        ShowErrorDialogMessage(result.msg);
                        
                    }else{
                        var user=$(".user-box-info.u-"+ID);
                        user.find("input.current-authority-value").val(authority);
                        user.find(".apply-aurhority").hide();
                    }
                }catch(e){                                    
                    $(".error").html(e.message);
                }
            });
        });
    });
</script>
<div class="pl4 pb4">
    <p>
        <b style="color: red">
            Chức năng đa người dùng ( quản lý và nâng cấp người dùng ) đã được tắt. <br/>
            Mọi thay đổi phân quyền đều không được ghi nhận.<br/>
            Chức năng đa người dùng cho phép phân quyền quản lý các chức năng hệ thống cho nhiều người dùng khác nhau.<br/>
            Có hỗ trợ ghi vết, lịch sử sử dụng, chặn ip .<br/>
            Vui lòng liên hệ <tt>KhuongXuanTruong@gmail</tt> để được hỗ trợ.
        </b>
    </p>
</div>
{{foreach $Data["Accs"] as $ac}}
    <div class="grid_x pl4 pb4 user-box-info u-{{$ac->ID}}">
        <div class="bdccc gadiend-white pr">
            <div class="bdbccc lh20 pl20 pt2 pb2 pr">
                <span class="authority-name">{{$ac->AuthorityName}}</span>
                {{if $_SESSION["ADP"]["USER"]["Position"] > 1 and $ac->Position<=1}}
                    <div  class="pa t4 r4">
                        <img class="hover50 hidden apply-aurhority" src="{{base_url()}}syslib/sysimages/16/action_check.png"/>
                        <img class="hover50 user-opt s-p-e" title="" 
                             
                             src="{{base_url()}}syslib/sysimages/16/node_select_previous.png"/>
                    </div>
                {{/if}}
            </div>
            <div class="pt4 pb4 pl4 pr4 grid_x bdrccc">
                <img class="grid_1" src="{{$ac->Picture}}"/>
            </div>
            <div class="pt4 pb4 pl4 pr4 grid_x lh16">
                <table>
                    <tr>
                        <td class="pr12">Name</td>
                        <td>{{$ac->Name}}</td>
                    </tr>
                    <tr>
                        <td class="pr12">Email</td>
                        <td>
                            {{if $_SESSION["ADP"]["USER"]["Position"]>=$ac->Position}}
                                {{$ac->Email}}
                            {{else}}
                                ********@gmail.com
                            {{/if}}
                        </td>
                    </tr>

                </table>
            </div>
            <div class="clear"></div>
            <div class="bdtccc authoritys-box {{if $ac->Position==0}}hidden{{/if}}">
                {{foreach $Data["Aus"] as $au}}
                    <div class="pt4 pb4 pl4 pr4" title="{{$au->Note}}">
                        <div class="grid_2" style="height: 20px">
                            <div id="{{$ac->ID}}-{{$au->Keyword}}" class="bdccc swb 
                                {{if $ac->Authority|strpos:$au->Keyword or $ac->Authority=="admin"}}on{{/if}}
                                {{if $ac->Position>1}}dis{{/if}}
                                ">
                            </div>
                        </div>
                        <div class="grid_x lh20">{{$au->Name}}</div>
                        <div class="clear"></div>
                    </div>
                {{/foreach}}
            </div>
            <div class="bdlccc bdrccc bdbccc gadiend-white pa l0 ml-1 r0 mr-1 user-up-down-graded hidden s-p-e c-w-c-b" style="top: 74px">
                <div class="pt4 pb4 pl4 pr4">
                    {{if $ac->Position<=1}}
                        <div class="upgraded {{if $ac->Position==1}}hidden{{/if}}">
                            do you want <span onclick="upgraded('{{$ac->ID}}')" class="a">upgraded</span> this the user?<br/>
                        </div>
                        <div class="downgraded {{if $ac->Position==0}}hidden{{/if}}">
                            do you want <span onclick="downgraded('{{$ac->ID}}')" class="a">downgraded</span> this the user?
                        </div>
                    {{/if}}
                </div>
            </div>
            <input type="hidden" class="classic-input user-id" value="{{$ac->ID}}"/>
            <input type="hidden" class="classic-input authority-value" value="{{$ac->Authority}}"/>
            <input type="hidden" class="classic-input current-authority-value" value="{{$ac->Authority}}"/>
        </div>
        <div class="clear"></div>
    </div>
{{/foreach}}
<script>
    
    function upgraded(ID){
            if(isrunning) return;
            var url = "{{base_url()}}APanel/user/upgraded/940cc81cec5c7e119162e62bd57710f0d"
            var data={
                ID : ID
            }
            isrunning=true;
            jqxAjax(url,data,function(result){
                isrunning=false;
                try{
                    if(result.code<0){
                        ShowErrorDialogMessage(result.msg);
                        
                    }else{
                        var user=$(".user-box-info.u-"+ID);
                        user.find(".authoritys-box").show();
                        user.find(".downgraded").show();
                        user.find(".upgraded").hide();
                        user.find(".user-up-down-graded").hide();
                        user.find(".authority-name").html("User");
                    }
                }catch(e){                                    
                    $(".error").html(e.message);
                }
            });
        
    }
    function downgraded(ID){
            if(isrunning) return;
            var url = "{{base_url()}}APanel/user/downgraded/940cc81cec5c7e119162e62bd57710f0d"
            var data={
                ID : ID
            }
            isrunning=true;
            jqxAjax(url,data,function(result){
                isrunning=false;
                try{
                    if(result.code<0){
                        ShowErrorDialogMessage(result.msg);
                        
                    }else{
                        var user=$(".user-box-info.u-"+ID);
                        user.find(".authoritys-box").hide();
                        user.find(".downgraded").hide();
                        user.find(".upgraded").show();
                        user.find(".user-up-down-graded").hide();
                        user.find(".swb").jqxSwitchButton({checked:false});
                        user.find("input.authority-value").val("");
                        user.find("input.current-authority-value").val("");
                        user.find(".authority-name").html("Guest");
                    }
                }catch(e){                                    
                    $(".error").html(e.message);
                }
            });
        
    }
    
</script>
<style>
    table {
        display: inline-block;
        border-collapse: collapse;
    }
    th, td {
        display: table-cell;
    }
    tr {
        display: table-row;
    }
    .jqx-switchbutton-label{font-size: 11px}
    .jqx-switchbutton-label-on
    {
        filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#3065c4', endColorstr='#75adfc',GradientType=0 ); /* IE6-9 */    
        background-image: linear-gradient(bottom, rgb(118,174,252) 20%, rgb(48,103,197) 62%);
        background-image: -o-linear-gradient(bottom, rgb(118,174,252) 20%, rgb(48,103,197) 62%);
        background-image: -moz-linear-gradient(bottom, rgb(118,174,252) 20%, rgb(48,103,197) 62%);
        background-image: -webkit-linear-gradient(bottom, rgb(118,174,252) 20%, rgb(48,103,197) 62%);
        background-image: -ms-linear-gradient(bottom, rgb(118,174,252) 20%, rgb(48,103,197) 62%);
        background-image: -webkit-gradient(
                linear,
                left bottom,
                left top,
                color-stop(0.2, rgb(118,174,252)),
                color-stop(0.62, rgb(48,103,197))
        );                    
        color: #fff;
        text-shadow: 0px -1px 1px #000;                                   
    }
    .jqx-widget.jqx-switchbutton{
        -webkit-border-radius: 18px;
        -moz-border-radius: 18px;
        border-radius: 18px;
    }
    .jqx-switchbutton-label .jqx-disableselect{margin-top: 2px !important}
/*    .jqx-switchbutton-thumb{
        -webkit-border-radius: 18px;
        -moz-border-radius: 18px;
        border-radius: 18px;
    }*/
</style>
